//
//  MyViewController.m
//  PhoenixNews
//
//  Created by dllo on 16/1/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MyViewController.h"
#import "PhoneixNews.pch"
#import "DetaileBelleViewController.h"
#import "MyCollectionViewCell.h"
@interface MyViewController ()<UITableViewDelegate, UITableViewDataSource, UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) UICollectionView *collection;
@property (nonatomic, retain) NSMutableArray *mutableArray;// 内容数组
@property (nonatomic, retain) NSMutableArray *imagemutableArray;// 图片数组
@property (nonatomic, retain) NSMutableArray *titleArray;// 阅读 等数组
@property (nonatomic, retain) NSMutableArray *titleImage;// 阅读等图片
@end

@implementation MyViewController
- (void)dealloc {
    [_tableView release];
    [_imagemutableArray release];
    [_titleArray release];
    [_titleImage release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_tableView];
    [_tableView release];
    // 内容数组
    self.mutableArray = [[NSMutableArray alloc] initWithObjects:@"我的消息", @"金币商城", @"我的任务", @"我的钱包", @"我的邮箱", nil];
    [_mutableArray release];
    // 图片数组
    self.imagemutableArray = [[NSMutableArray alloc] initWithObjects:@"image",@"imageTwo", @"imageThree", @"imageFour", @"imageFive", nil];
    // 阅读等数组
    self.titleArray = [[NSMutableArray alloc] initWithObjects:@"阅读", @"收藏", @"跟帖", @"金币", nil];
    // 阅读图片数组
    self.titleImage = [[NSMutableArray alloc] initWithObjects:@"Yue", @"Xing", @"Gen", @"Jin", nil];
}

#pragma mark -TableView协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _mutableArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text = _mutableArray[indexPath.row];// 类型
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;// 辅助标题
    cell.imageView.image = [UIImage imageNamed:_imagemutableArray[indexPath.row]];// 图片
    return cell;
}
// cell点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.item == 0) {
        NSLog(@"😄");
    }else if (indexPath.item == 1) {
        // 金币商城网址
       NSString *string = @"http://c.3g.163.com/CreditMarket/default.html?source=discovery";
      DetaileBelleViewController *detail = [[DetaileBelleViewController alloc] init];
        detail.imageStr = string;
        // 跳转到详情页
        [self.navigationController pushViewController:detail animated:YES];
    }
}


// 头试图高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 260;
}
// 头试图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 300)];
    headView.backgroundColor = [UIColor redColor];
    UIImageView *headImage = [[UIImageView alloc] initWithFrame:CGRectMake(headView.frame.size.width / 2 - 30, headView.frame.size.height / 3 - 40, 50, 50)];
    headImage.image = [UIImage imageNamed:@"headImage"];
    [headView addSubview:headImage];
    UICollectionViewFlowLayout *layou = [[UICollectionViewFlowLayout alloc] init];
    layou.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layou.itemSize = CGSizeMake(90, 800/ 5);
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, headView.frame.size.height - 110, headView.frame.size.width, 70) collectionViewLayout:layou];
    self.collection.delegate = self;
    self.collection.dataSource = self;
    self.collection.showsHorizontalScrollIndicator = NO;
    self.collection.backgroundColor = [UIColor whiteColor];
    [_collection registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    [headView addSubview:_collection];
    [_collection release];
    return headView;
    
}
#pragma mark - COllection协议方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _titleImage.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
   MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.title.text = _titleArray[indexPath.row];
    
    cell.image.image = [UIImage imageNamed:_titleImage[indexPath.row]];
    
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
